import subprocess
import shlex

info_cmd = "echo 'info all'"
ggsci_cmd = "/home/oracle/oggformysql/ggsci"
info_args = shlex.split(info_cmd)
ggsc_args = shlex.split(ggsci_cmd)
info_process = subprocess.Popen(info_args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
                                shell=False)
ggsci_process = subprocess.Popen(ggsc_args, stdin=info_process.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
                                 shell=False)

lines_byte = ggsci_process.stdout.readlines()
for line_byte in lines_byte:
    line_str = line_byte.decode('UTF8')

    if line_str.startswith('MANAGER'):
        items = line_str.split();
        type = items[0]
        status = items[1]
        print(type + ":" + status)

    if line_str.startswith('EXTRACT') or line_str.startswith('REPLICAT'):
        items = line_str.split();
        type = items[0]
        status = items[1]
        name = items[2]
        print(type + ":" + status + ":" + name) 